package cn.wizzer.app.web.modules.controllers.platform.crown;

import cn.wizzer.app.crown.modules.models.CrownMatch;
import cn.wizzer.app.crown.modules.models.enums.BetsEnum;
import cn.wizzer.app.crown.modules.services.CrownBetService;
import cn.wizzer.app.crown.modules.services.CrownMatchService;
import cn.wizzer.app.crown.modules.services.order.CrownOrderService;
import cn.wizzer.framework.util.Result;
import cn.wizzer.framework.util.param.ParamVerify;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.adaptor.JsonAdaptor;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import java.util.Date;

/**
 * 后台利率管理
 *
 * @author
 */
@IocBean
@At("/platform/crown/bet")
public class CrownBetController {

    @Reference
    @Inject
    private CrownBetService betService;
    @Reference
    @Inject
    private CrownMatchService matchService;
    @Inject
    private CrownOrderService orderService;


    @At("")
    @Ok("beetl:/platform/crown/bet/index.html")
    @RequiresPermissions("crown.bet.list")
    public void index() {
    }


    /**
     * 赛事列表
     *
     * @param start
     * @param end
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @At("/data")
    @Ok("json:full")
    @RequiresPermissions("crown.bet.list")
    public Object data(@Param("searchKeyword") String searchKeyword,
                       @Param("stage") String stage,
                       @Param("start") Date start,
                       @Param("end") Date end,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        return Result.success(matchService.listPage(searchKeyword, stage, start, end, pageNumber, pageSize));
    }


    /**
     * 根据betType(全场、半场)查询某场比赛的投资内容
     *
     * @param matchId
     * @param betType
     * @return
     */
    @At("/edit")
    @Ok("json")
    public Object edit(@ParamVerify(required = true, name = "matchId") String matchId, @ParamVerify(name = "betType") BetsEnum betType) {
        return Result.success(matchService.composeMatch(betType, matchId));
    }


    /**
     * 修改利率、赛事保本
     *
     * @param match
     * @return
     */
    @At("/editDo")
    @Ok("json")
    @RequiresPermissions("crown.bet.edit")
    @AdaptBy(type = JsonAdaptor.class)
    public Object editDo(@Param("..") CrownMatch match) {
        betService.editDo(match);
        return Result.success();
    }


    /**
     * CrownBet类型集合(全场波胆、半场波胆、全场总入球)
     *
     * @return
     */
    @At
    @Ok("json")
    @RequiresPermissions("crown.bet.list")
    public Object betTypes() {
        return Result.success(BetsEnum.toList());
    }


}
